<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set the memory limit for the Lua environment</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="luasandbox.setcpulimit.html">« LuaSandbox::setCPULimit</a></li>
      <li style="float: right;"><a href="luasandbox.unpauseusagetimer.html">LuaSandbox::unpauseUsageTimer »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.luasandbox.html">LuaSandbox</a></li>
    <li>Set the memory limit for the Lua environment</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="luasandbox.setmemorylimit" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">LuaSandbox::setMemoryLimit</h1>
  <p class="verinfo">(PECL luasandbox &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">LuaSandbox::setMemoryLimit</span> &mdash; <span class="dc-title">Set the memory limit for the Lua environment</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-luasandbox.setmemorylimit-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>LuaSandbox::setMemoryLimit</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$limit</code></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
   Sets the memory limit for the Lua environment.
  </p>
  <p class="para">
   If this limit is exceeded, a <span class="classname"><a href="class.luasandboxmemoryerror.html" class="classname">LuaSandboxMemoryError</a></span>
   exception is thrown.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-luasandbox.setmemorylimit-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">limit</code></dt>

    <dd>

     <p class="para">
      Memory limit in bytes.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-luasandbox.setmemorylimit-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-luasandbox.setmemorylimit-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3441">
    <p><strong>示例 #1 Calling a Lua function</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;create&nbsp;a&nbsp;new&nbsp;LuaSandbox<br /></span><span style="color: #0000BB">$sandbox&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">LuaSandbox</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;a&nbsp;memory&nbsp;limit<br /></span><span style="color: #0000BB">$sandbox</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setMemoryLimit</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">50&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">1024&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">1024&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Run&nbsp;Lua&nbsp;code<br /></span><span style="color: #0000BB">$sandbox</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadString</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'local&nbsp;x&nbsp;=&nbsp;"x";&nbsp;while&nbsp;true&nbsp;do&nbsp;x&nbsp;=&nbsp;x&nbsp;..&nbsp;x;&nbsp;end'&nbsp;</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">call</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
PHP Fatal error:  Uncaught LuaSandboxMemoryError: not enough memory
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-luasandbox.setmemorylimit-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="luasandbox.getmemoryusage.html" class="methodname" rel="rdfs-seeAlso">LuaSandbox::getMemoryUsage()</a> - Fetch the current memory usage of the Lua environment</span></li>
    <li class="member"><span class="methodname"><a href="luasandbox.getpeakmemoryusage.html" class="methodname" rel="rdfs-seeAlso">LuaSandbox::getPeakMemoryUsage()</a> - Fetch the peak memory usage of the Lua environment</span></li>
    <li class="member"><span class="methodname"><a href="luasandbox.setcpulimit.html" class="methodname" rel="rdfs-seeAlso">LuaSandbox::setCPULimit()</a> - Set the CPU time limit for the Lua environment</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>